package com.dkd.manage.service.impl;

import java.util.List;
import com.dkd.common.utils.DateUtils;
import com.dkd.manage.domain.Novel;
import com.dkd.manage.mapper.NovelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.dkd.manage.mapper.NovelTitleMapper;
import com.dkd.manage.domain.NovelTitle;
import com.dkd.manage.service.INovelTitleService;

/**
 * 小说Service业务层处理
 * 
 * @author hm
 * @date 2025-03-12
 */
@Service
public class NovelTitleServiceImpl implements INovelTitleService 
{
    @Autowired
    private NovelTitleMapper novelTitleMapper;

    @Autowired
    private NovelMapper novelMapper;

    /**
     * 查询小说
     * 
     * @param id 小说主键
     * @return 小说
     */
    @Override
    public NovelTitle selectNovelTitleById(Long id)
    {
        return novelTitleMapper.selectNovelTitleById(id);
    }

    /**
     * 查询小说列表
     * 
     * @param novelTitle 小说
     * @return 小说
     */
    @Override
    public List<NovelTitle> selectNovelTitleList(NovelTitle novelTitle)
    {
        return novelTitleMapper.selectNovelTitleList(novelTitle);
    }

    /**
     * 新增小说
     * 
     * @param novelTitle 小说
     * @return 结果
     */
    @Override
    public int insertNovelTitle(NovelTitle novelTitle)
    {
        novelTitle.setCreateTime(DateUtils.getNowDate());
        int i = novelTitleMapper.insertNovelTitle(novelTitle);
        // 新建小说的时候也需要创建Novel
        Novel novel = new Novel();
        novel.setNovelId(novelTitle.getId());
        novel.setCreateTime(DateUtils.getNowDate());
        novel.setUpdateTime(DateUtils.getNowDate());
        novel.setNovel("内容未填充");
        novelMapper.insertNovel(novel);
        return i;
    }

    /**
     * 修改小说
     * 
     * @param novelTitle 小说
     * @return 结果
     */
    @Override
    public int updateNovelTitle(NovelTitle novelTitle)
    {
        novelTitle.setUpdateTime(DateUtils.getNowDate());
        return novelTitleMapper.updateNovelTitle(novelTitle);
    }

    /**
     * 批量删除小说
     * 
     * @param ids 需要删除的小说主键
     * @return 结果
     */
    @Override
    public int deleteNovelTitleByIds(Long[] ids)
    {
        return novelTitleMapper.deleteNovelTitleByIds(ids);
    }

    /**
     * 删除小说信息
     * 
     * @param id 小说主键
     * @return 结果
     */
    @Override
    public int deleteNovelTitleById(Long id)
    {
        return novelTitleMapper.deleteNovelTitleById(id);
    }
}
